package com.bookheaven.core.entity;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import entity.base.BaseEntity;

@Entity
@Table(name = "COMMENT")
public class Comment extends BaseEntity {
	
	private static final long	serialVersionUID	= 1655590074823318622L;
	
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "BOOK_REF", nullable = false)
	private Book				commentBook;
	
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "USER_REF", nullable = false)
	private User				commentUser;
	
	@Column(name = "CONTENT", nullable = false, length = 255)
	private String				commentContent;
	
	@Column(name = "COMMENT_DATE")
	private Date				commentDate;
	
	public Book getCommentBook() {
		return commentBook;
	}
	
	public void setCommentBook(Book commentBook) {
		this.commentBook = commentBook;
	}
	
	public User getCommentUser() {
		return commentUser;
	}
	
	public void setCommentUser(User commentUser) {
		this.commentUser = commentUser;
	}
	
	public String getCommentContent() {
		return commentContent;
	}
	
	public void setCommentContent(String commentContent) {
		this.commentContent = commentContent;
	}
	
	public Date getCommentDate() {
		return commentDate;
	}
	
	public void setCommentDate(Date commentDate) {
		this.commentDate = commentDate;
	}
	
	@Override
	public String toString() {
		return commentUser.getUserName() + "@" + commentBook.getBookName() + ": \"" + commentContent + "\"";
	}
	
}